package com.gscitysfy.cus.drain.modules.pipe.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;
import com.gscitysfy.cus.drain.annotations.DictTranslation;
import com.gscitysfy.cus.drain.annotations.FieldParam;
import com.gscitysfy.cus.drain.constants.DicConstant;
import com.gscitysfy.cus.drain.modules.pipe.entity.DrainPipeNetworkFlaw;
import com.gscitysfy.cus.drain.modules.pipe.service.IDrainPipeNetworkFlawService;
import com.gscitysfy.cus.drain.modules.pipe.vo.DrainPipeNetworkFlawVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 钱小龙
 * @since 2022-11-15 10:50:56
 */
@RestController
@RequestMapping("/pipe/drain-pipe-network-flaw")
@Slf4j
@Tag(name = "监测缺陷管理")
public class DrainPipeNetworkFlawController {

    @Resource
    private IDrainPipeNetworkFlawService drainPipeNetworkFlawService;


    /**
     * APP/PC分页获取检测缺陷列表
     * @param drainPipeNetworkFlawVo
     * @return
     */
    @PostMapping("/getFlawListByCondition")
    @Operation(summary = "APP/PC分页获取检测缺陷列表", description = "APP/PC分页获取检测缺陷列表",
            responses = {
            @ApiResponse(description = "APP/PC分页获取检测缺陷列表", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainPipeNetworkFlaw.class)))
    })
    @Parameters({
            @Parameter(required = false, name = "cmFlawType", description = "缺陷类别"),
            @Parameter(required = false, name = "cmFlawLevel", description = "缺陷等级"),
            @Parameter(required = false, name = "cmFlawName", description = "缺陷名称"),
            @Parameter(required = false, name = "cmFlawPlace", description = "缺陷位置"),
            @Parameter(required = false, name = "cmStartFlawTime", description = "检测开始时间"),
            @Parameter(required = false, name = "cmEndFlawTime", description = "检测结束时间"),
            @Parameter(required = false, name = "cmPlanPipeType", description = "管网类型"),
            @Parameter(required = false, name = "cmKid", description = "主键id")  ,
            @Parameter(required = false, name = "size", description = "分页每页条数"),
            @Parameter(required = true, name = "current", description = "当前页")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.FLAW_TYPE, targetField = "cmFlawType"),
            @FieldParam(dictType = DicConstant.FLAW_LEVEL, targetField = "cmFlawLevel"),
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmPlanPipeType")
    })
    public Result<Page<DrainPipeNetworkFlaw>> getFlawListByCondition(@Parameter(hidden = true) @RequestBody DrainPipeNetworkFlawVo drainPipeNetworkFlawVo) {
        Page<DrainPipeNetworkFlaw> page = new Page<>();
        page.setSize(drainPipeNetworkFlawVo.getSize()); page.setCurrent(drainPipeNetworkFlawVo.getCurrent());
        Page<DrainPipeNetworkFlaw> flawListByCondition = drainPipeNetworkFlawService.getFlawListByCondition(page, drainPipeNetworkFlawVo);
        return Result.content(flawListByCondition);
    }


    /**
     * 上报缺陷
     * @param drainPipeNetworkFlaw
     * @return
     */
    @PostMapping("/save-flaw")
    @Operation(summary = "上报缺陷", description = "上报缺陷",
            responses = {
                    @ApiResponse(description = "上报缺陷", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainPipeNetworkFlaw.class)))
            })
    @Parameters({
            @Parameter(required = false, name = "cmFlawType", description = "缺陷类别"),
            @Parameter(required = false, name = "cmFlawLevel", description = "缺陷等级"),
            @Parameter(required = false, name = "cmFlawName", description = "缺陷名称"),
            @Parameter(required = false, name = "cmFlawPlace", description = "缺陷位置"),
            @Parameter(required = false, name = "cmFlawLng", description = "经度"),
            @Parameter(required = false, name = "cmFlawLat", description = "纬度"),
            @Parameter(required = false, name = "cmPipeId", description = "关联管网id"),
            @Parameter(required = false, name = "cmFileReportId", description = "上传附件id")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.FLAW_TYPE, targetField = "cmFlawType"),
            @FieldParam(dictType = DicConstant.FLAW_LEVEL, targetField = "cmFlawLevel")
    })
    public Result saveFlaw(@RequestBody DrainPipeNetworkFlaw drainPipeNetworkFlaw) {
        return Result.content(drainPipeNetworkFlawService.saveFlaw(drainPipeNetworkFlaw));
    }



    /**
     * Gis列表查询
     * @param drainPipeNetworkFlawVo
     * @return
     */
    @PostMapping("/get-flaw")
    @Operation(summary = "Gis列表查询", description = "Gis列表查询",
            responses = {
                    @ApiResponse(description = "Gis列表查询", content = @Content(mediaType = "application/json", schema = @Schema(implementation = DrainPipeNetworkFlaw.class)))
            })
    @Parameters({
            @Parameter(required = false, name = "cmPlanPipeType", description = "管网类型")
    })
    @DictTranslation({
            @FieldParam(dictType = DicConstant.FLAW_TYPE, targetField = "cmFlawType"),
            @FieldParam(dictType = DicConstant.FLAW_LEVEL, targetField = "cmFlawLevel"),
            @FieldParam(dictType = DicConstant.PLAN_PIPE_TYPE, targetField = "cmPlanPipeType")
    })
    public Result getFlaw(@Parameter(hidden = true) @RequestBody DrainPipeNetworkFlawVo drainPipeNetworkFlawVo) {
        return Result.content(drainPipeNetworkFlawService.getFlaw(drainPipeNetworkFlawVo));
    }
}
